package cn.ld.module.system.dal.mapper.dept;

import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.dept.vo.dept.DeptListInVO;
import cn.ld.module.system.dal.entity.dept.DeptEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface DeptMapper extends BaseMapperX<DeptEntity> {

    default List<DeptEntity> selectList(DeptListInVO inVO) {
        return selectList(new LambdaQueryWrapperX<DeptEntity>()
                .likeIfPresent(DeptEntity::getName, inVO.getName())
                .eqIfPresent(DeptEntity::getStatus, inVO.getStatus()));
    }

    default DeptEntity selectByParentIdAndName(Long parentId, String name) {
        return selectOne(DeptEntity::getParentId, parentId, DeptEntity::getName, name);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(DeptEntity::getParentId, parentId);
    }

    default List<DeptEntity> selectListByParentId(Collection<Long> parentIds) {
        return selectList(DeptEntity::getParentId, parentIds);
    }

    default List<DeptEntity> selectListByLeaderUserId(Long id) {
        return selectList(DeptEntity::getLeaderUserId, id);
    }

}
